*note: there are slight variation in results due to lasso selection of covariates

capture log close 

clear

*set your working directory here. make sure to create Figures and Tables subfolders so the code will run.
*cd "" 

*install required packages
ssc install cibar, replace
net describe gr0002_3, from(http://www.stata-journal.com/software/sj4-3)
net install gr0002_3.pkg
net describe st0085_2, from(http://www.stata-journal.com/software/sj14-2)
net install st0085_2.pkg

***************
*zip race data*
***************

*import zip/zcta crosswalk
import delimited "zip_zcta_xref.csv", varnames(1) stringcols(_all) clear 

save "zip_zcta_xref.dta", replace

*import Census data
import delimited "racezip.csv", varnames(1) clear 

*extract zip code
gen zcta=substr(geography,10,5)

*calculate nonwhite percentage
gen nonwhite_pct=100-((countracetotalpopulationoneracew/countracetotalpopulation)*100)

*keep only ZCTA and nonwhite percentage
keep zcta nonwhite_pct

merge 1:m zcta using "zip_zcta_xref.dta"
tab _merge
drop if _merge!=3
drop _merge
rename zip_code qZip

*save data 
save "nonwhitezip.dta", replace

******************
*demographic data*
******************

forval i=1/5 {
	import delimited using "demos`i'.csv", clear
	save "demos`i'.dta", replace
	}

use "demos1.dta", clear
forval i=2/5 {
	append using "demos`i'.dta"
	}

drop starttimeamericanew_york completiontimeamericanew_york completiontype completioncode payment bonus fees status

*remove duplicate observation (other one for this person includes ethnicity)
drop if participantid=="06BBF24C03A64E55BDE8CBEA1EB6DE03" & ethnicity==""
	
rename participantid participantId
recast str32 participantId
save "demos.dta", replace

*****************
*main study data*
*****************

*open study data 
use "2024 Experiments in Politics final study_May 9, 2024_14.04.dta", clear

count

*drop responses voided by survey programming error
sort StartDate
drop if StartDate<tc(05may2024 22:21:06)

count

*drop everyone not in experimental sample
keep if no_look_up_==3

count

*identify duplicate observations
duplicates report participantId
duplicates tag participantId, gen(dupey)
list participantId no_look_up_ effects_Q1 eQ2 eQ3 eQ4 mQ1 mQ2 mQ3 mQ4 troll StartDate if dupey>0

*drop second response for anyone who appears more than once (n=3 x 2 responses)
sort participantId StartDate
bysort participantId: gen order=_n
drop if order==2
drop order

count

*confirm no duplicates
list participantId no_look_up_ effects_Q1 eQ2 eQ3 eQ4 mQ1 mQ2 mQ3 mQ4 troll StartDate if dupey>0
drop dupey

*merge in demographic data from Connect
recast str32 participantId
merge 1:1 participantId using "demos.dta"

*1 person has a missing participant ID and is thus missing demographic variables; a bunch are in demographics file but not in final experimental sample and their observations are removed (by the drop if _merge==2)
tab _merge 
drop if _merge==2
drop _merge

*sample size afterward
count

*************************
*pre-treatment variables*
*************************

*age group (18-24, 25-34, 35-44, 45-54, 55-64, 65-74, 75-84, 85+)
tab age

*education level (less than a high school degree to doctorate)	
tab education 
egen education_group=group(education)

*sex (male, female, intersex)	
tab sex 
gen male=.
replace male=0 if sex!="Male" & sex!=""
replace male=1 if sex=="Male"
tab male

*also have gender 
tab gender 

*ethnicity (0 if not of Hispanic, Latino, or Spanish origin, 1 if yes)
tab ethnicity
gen hispanic=.
replace hispanic=0 if ethnicity=="No, not of Hispanic, Latino, or Spanish origin" & ethnicity!=""
replace hispanic=1 if ethnicity!="No, not of Hispanic, Latino, or Spanish origin" & ethnicity!=""
tab hispanic

*household income (less than $10,000 to $250,000 or more)	
tab householdincome
egen income_group=group(householdincome) 

*race (many categories)
tab race
egen race_group=group(race) 

*make a white variable for RQ2
gen white=.
replace white=0 if race!="White"
replace white=1 if race=="White"

tab white hispanic, cell

*employment status (many categories)
tab employment 

*government assistance (1 if yes, 0 if no)
replace govt_assistance=0 if govt_assistance==2
tab govt_assistance

*party support and lean / strength of partisan identification (see below; used to make 0/1 indicators of D/R party affiliation including leaners)

*We will create an indicator for Democrats that takes the value of 1 for people who identify as Democrat or lean Democrat and 0 otherwise and an indicator of Republicans that takes the value of 1 for people who identify as Republican or lean Republican and 0 otherwise.

gen dem=0
replace dem=1 if party==2 | ind_party==2

gen rep=0
replace rep=1 if party==1 | ind_party==1

tab dem rep, missing cell

*respondents' feelings towards political figures, racial groups, and political parties on a 0-100 point scale, where 0 = not favorable/don't care and 100= favorable/warm attitudes
rename thermometer_2 white_therm
rename thermometer_3 black_therm
rename thermometer_5 biden_therm 
rename thermometer_6 trump_therm
rename thermometer_7 republican_therm
rename thermometer_8 democrat_therm

*participants' home ownership status (0 = not homeowner, 1 = homeowner)
gen homeowner_binary=.
replace homeowner_binary=0 if home_ownership>2 & home_ownership<7
replace homeowner_binary=1 if home_ownership<3

*type of home they live in
tab home_type

*how affordable respondents believe their own housing is on a four-point scale where 1 = "Not at all affordable" and 4 = "Very affordable"
gen affordability=.
replace affordability=1 if affordable==4
replace affordability=2 if affordable==3
replace affordability=3 if affordable==2
replace affordability=4 if affordable==1

*attention check passage rates
tab attn_1
tab attn_2

*availability of affordable housing in the respondents' area on a four-point scale where 1 = "Strongly disagree" and 4 = "Strongly agree"
tab find_aff_easy
tab prob_pay_ind

*whether respondents know others who have trouble paying for housing in their area or do not know anyone who has trouble paying for housing in their area on a four-point scale where 1 = "Strongly disagree" and 4 = "Strongly agree"
tab prob_pay_social
tab no_prob_paying

*respondents' sense of connectedness to neighborhood and bond with others in neighborhood on a four-point scale where 1 = "Strongly disagree" and 4 = "Strongly agree"
tab connected
tab good_bond

*whether respondents support or oppose building more affordable housing near their homes on a four-point scale where 1 = "Strongly disagree" and 4 = "Strongly agree"
tab support_aff_pre
tab oppose_aff

*percent nonwhite in respondent zipcode (calculated from provided zipcode using Census data on ZCTAs)
merge m:1 qZip using "nonwhitezip.dta"
tab _merge
drop if _merge==2
tab qZip if _merge==1 /*9 missing observations*/
drop _merge 
su nonwhite_pct, detail

*We will create indicators for tercile of percent nonwhite in respondent zipcode among white respondents.
xtile nonwhite_pct_terc=nonwhite_pct, nq(3)
tab nonwhite_pct_terc

xtile nonwhite_pct_quint=nonwhite_pct, nq(5)
tab nonwhite_pct_quint

*affordable_area = mean belief that affordable housing is available (reverse-coded for "It is difficult to find housing I can afford")
gen affordable_area=(find_aff_easy+abs(prob_pay_ind-5))/2
tab affordable_area

*know_others_difficulty = mean knowledge of other people who have trouble paying for housing (reverse-coded for "No one I know has problems paying for housing")
gen know_others_difficulty=(prob_pay_social+abs(no_prob_paying-5))/2
tab know_others_difficulty

*neighborhood_bonds = mean agreement on sense of connectedness to neighborhood and bond with others in neighborhood 
gen neighborhood_bonds=(connected+good_bond)/2
tab neighborhood_bonds

*affordable_housing_support_pre = mean support for building more affordable housing near where they live (reverse-coded for "I oppose building more affordable housing near where I live")
gen affordable_housing_support_pre=(support_aff_pre+abs(oppose_aff-5))/2
tab affordable_housing_support_pre

*difference in racial affect = white feeling thermometer - black feeling thermometer (white respondents only)
gen feeling_diff=white_therm-black_therm

gen feeling_diff_terc=.
replace feeling_diff_terc=2 if feeling_diff>0 & feeling_diff!=.
replace feeling_diff_terc=1 if feeling_diff==0 & feeling_diff!=.
replace feeling_diff_terc=0 if feeling_diff<0 & feeling_diff!=.

***********************
*manipulated variables*
***********************

*An indicator that takes the value of 1 if the respondent is randomly assigned to the effects correction treatment and 0 otherwise (no correction or characteristics correction).
gen effects_treatment=(group=="T1_effects")

*An indicator that takes the value of 1 if the respondent is randomly assigned to the characteristics correction treatment and 0 otherwise (no correction or effects correction).
gen characteristics_treatment=(group=="T2_eligibility")

*An indicator that takes the value of 1 if the respondent answered effects questions before characteristics questions and 0 otherwise.
gen effects_first=(first=="effects")

*An indicator that takes the value of 1 if the respondent answered questions about affordable housing two miles away before answering questions about affordable housing one-eighth of a mile away and 0 otherwise.
gen two_first=(FL_534_DO_Post_treatmentoutcome0==1)

****************************************
*descriptives of ask/ask-tell questions*
****************************************

tab effects_Q1
tab eQ2
tab eQ3
tab eQ4

gen impacts_correct=(effects_Q1==2)+(eQ2==1)+(eQ3==3)+(eQ4==2)
tab impacts_correct
tab impacts_correct group, col

tab mQ1
tab mQ2
tab mQ3
tab mQ4

gen stereotypes_correct=(mQ1==3)+(mQ2==1)+(mQ1==3)+(mQ1==1)
tab stereotypes_correct 
tab stereotypes_correct group, col

**************************
*post-treatment variables*
**************************

*if they support/oppose building more affordable housing in their state on a four-point scale where 1 = "Strongly oppose" and 4 = "Strongly support"
rename support_state support_state_old
gen support_state=abs(5-support_state_old)
tab support_state

gen vote_state=abs(5-state_tax)

*if they would support/oppose building affordable housing one-eighth of a mile (2 min. walk) away from where they live on a four-point scale where 1 = "Strongly oppose" and 4 = "Strongly support"
rename support_8th support_8th_old
gen support_8th=abs(5-support_8th)
tab support_8th

*if they would support/oppose a new tax referendum to reallocate local taxes to build affordable housing one-eighth of a mile (2 min. walk) from where they live on a four-point scale where 1 = "Strongly oppose" and 4 = "Strongly support"
rename vote_8th vote_8th_old
gen vote_8th=abs(5-vote_8th_old)
tab vote_8th

*perceived effects (e.g., on traffic congestion, property values, green spaces, quality of schools, etc.) of building affordable housing one-eighth of a mile (2 min. walk) away on a five-point scale where 1 = "Much worse" and 5 = "Much better"
foreach var of varlist traffic_8 prop_value_8 ethnic_8 crime_8 green_8 schools_8 {
	tab `var'
} 

*if they would support/oppose building affordable housing two miles (40 min. walk) away from where they live on a four-point scale where 1 = "Strongly oppose" and 4 = "Strongly support"
rename support_2 support_2_old
gen support_2=abs(5-support_2)
tab support_2

*if they would support/oppose a new tax referendum to reallocate local taxes to build affordable housing two miles (40 min. walk) from where they live on a four-point scale where 1 = "Strongly oppose" and 4 = "Strongly support"
rename vote_2 vote_2_old
gen vote_2=abs(5-vote_2_old)
tab vote_2

*survey error: vote_2 response options were "Yes, I would definitely vote in favor of this referendum" to "No, I would definitely vote against this referendum"

reg vote_8th support_8th
reg vote_2 support_2
reg vote_state support_state
pwcorr vote_8th support_8th vote_2 support_2 vote_state support_state

*perceived effects (e.g., on traffic congestion, property values, green spaces, quality of schools, etc.) of building affordable housing two miles (40 min. walk) away on a five-point scale where 1 = "Much worse" and 5 = "Much better"
foreach var of varlist traffic_2 prop_value_2 ethnic_2 crime_2 green_2 school_2 {
	tab `var'
} 

*whether statements about the effects and characteristics of affordable housing are true or false (where 1=an accurate answer and 0=an inaccurate answer)
gen manip_crime_correct=(manip_crime_1_0==1)
gen manip_blend_correct=(manip_blend_1==1)
gen manip_pv_neg_correct=(manip_pv_neg_2==2)
gen manip_noben_correct=(manip_noben_2==2)

gen manip_pv_1_correct=(manip_pv_1==1)
gen manip_crime_1_correct=(manip_crime_1==1)
gen manip_kids_2_correct=(manip_kids_2==2)
gen manip_urban_2_correct=(manip_urban_2==2)

*support_18 = mean support for building affordable housing at the 1/8-mile distance (mean of support and tax referendum items)
gen support_18_combined=(support_8th+vote_8th)/2

*support_2 = mean support for building affordable housing at the two-mile distance (mean of support and tax referendum items)
gen support_2_combined=(support_2+vote_2)/2

*support_state = mean support for building affordable housing at the state level (mean of support and tax referendum items)
gen support_state_combined=(support_state+vote_state)/2

*support: mean support for building affordable housing (mean of support and tax referendum items at state level and one-eighth and two-mile distances)
gen support=(support_8th+support_2+support_state+vote_8th+vote_2+vote_state)/6

*housing_effect_18 = mean perceived effect of affordable housing one-eighth of a mile away (mean of six measures: traffic congestion, local property values, racial/ethnic makeup of neighborhood, crime rates, green spaces, quality of schools) 
gen housing_effect_18=(traffic_8+prop_value_8+ethnic_8+crime_8+green_8+schools_8)/6

*housing_effect_2 =  mean perceived effect of affordable housing one-eighth of a mile away  (mean of six measures: traffic congestion, local property values, racial/ethnic makeup of neighborhood, crime rates, green spaces, quality of schools) 
gen housing_effect_2=(traffic_2+prop_value_2+ethnic_2+crime_2+green_2+school_2)/6

*effect = NOT preregistered (error) mean of all of both measures
gen effects=(traffic_8+prop_value_8+ethnic_8+crime_8+green_8+schools_8+traffic_2+prop_value_2+ethnic_2+crime_2+green_2+school_2)/12

*exploratory - targeted measures
gen effects_targeted=(prop_value_8+crime_8+prop_value_2+crime_2)/4

*exploratory - untargeted measures
gen effects_untargeted=(traffic_8+ethnic_8+green_8+schools_8+traffic_2+ethnic_2+green_2+school_2)/8

*effects_accuracy = mean accuracy of evaluations of statements about the effects of affordable housing
gen effects_accuracy=(manip_crime_correct+manip_blend_correct+manip_pv_neg_correct+manip_noben_correct)/4
tab effects_accuracy

*characteristics_accuracy = mean accuracy of evaluations of statements about the characteristics of affordable housing
gen characteristics_accuracy=(manip_pv_1_correct+manip_crime_1_correct+manip_kids_2_correct+manip_urban_2_correct)/4
tab characteristics_accuracy

****************************
*analysis: respondent-level*
****************************

*We will compute treatment effects via OLS with robust standard errors clustered by respondent where appropriate. 

*We will use a lasso variable selection procedure to determine the set of prognostic covariates to include in any respondent-level models. Each model listed below will also include the set of controls selected according to the process described below. If one or more levels (e.g., age group "18-24") are selected from a factor variable, we will include only the selected level(s) in the model. Below is the set of candidate variables that we will select from (as measured pretreatment) -- if not otherwise stated, these variables will be treated as continuous:

/*Education (factor variable)
Age group (18-24, 25-34, 35-44, 45-54, 55-64, 65-74, 75-84, 85+) (factor variable)
Male (1/0) 
Democrats (1/0; identifiers + leaners)
Republicans (1/0; identifiers + leaners)
Hispanic (1/0)
White (1/0)
White Non-Hispanic (1/0)
Race (factor variable)
Income (factor variable)
Homeowner (1/0)
Home type (factor variable)
Employment status (factor variable)
Government assistance (1/0)
Feelings toward political figures, racial groups, and parties (0-100; entered separately)
How affordable their housing is (1-4)
affordable_area (mean; 1-4)
know_others_difficulty (mean; 1-4)
neighborhood_bonds (mean; 1-4)
affordable_housing_support_pre (mean; 1-4)
*/

*All models will also control for which set of affordable housing knowledge questions appeared first (i.e., an indicator for effects questions appearing first) as well as which set of affordable housing opinion questions appeared first (i.e., an indicator for whether the respondent answered questions about affordable housing two miles away first). 

/*H2: Participants who receive corrective information will be more likely to support building affordable housing (H2a) and view its effects more positively (H2b).
RQ1: Will the effects of corrections focused on the perceived effects of affordable housing differ from those focused on the characteristics of affordable housing? 
To test H2 and RQ1, we will run the following model at the respondent level: 

Y = B0 + B1*effects_treatment + B2*characteristics_treatment

where Y = mean support for affordable housing (mean for all distances) and mean perception of the effects of affordable housing (mean for all distances).

We will test RQ1 by testing B1-B2 in each model.*/

*deviation: remove white and whitenonhispanic 

*deviation: too much missingness in hispanic, omit from lasso
tab hispanic, missing

****************
*H2/RQ1 section*
****************

*H2/RQ1 support lasso
lasso linear support i.education_group i.age i.male 1.dem 1.rep i.race_group i.income_group homeowner_binary home_type i.employment govt_assistance white_therm black_therm biden_therm trump_therm republican_therm democrat_therm affordability affordable_area know_others_difficulty neighborhood_bonds affordable_housing_support_pre, rseed(1234)
local support_ctl=e(allvars_sel) 

*H2/RQ1 support reg
reg support characteristics_treatment effects_treatment effects_first two_first `support_ctl', robust

*difference in treatment effects
lincom characteristics_treatment-effects_treatment
est store h2support

*exploratory with no lasso covariates for verification
reg support characteristics_treatment effects_treatment effects_first two_first, robust
lincom characteristics_treatment-effects_treatment

*variation by distance order
reg support characteristics_treatment##two_first effects_treatment##two_first effects_first `support_ctl', robust
est store h2support_twofirst

*make group variable for Figures
gen groupnum=.
replace groupnum=1 if group=="control"
replace groupnum=2 if group=="T2_eligibility"
replace groupnum=3 if group=="T1_effects"

label def grouplab 1 "Control" 2 "Stereotypes" 3 "Impacts"
label val groupnum grouplab

*bar graph
cibar support, over(groupnum) graphopts(scheme(lean1) legend(on ring(0) position(1) col(1) bcolor(white) region(lstyle(solid))) ytitle("") ylabel(4 `""Strongly" "support""' 3 `""Somewhat" "support""' 2 `""Somewhat" "oppose""' 1 `""Strongly" "oppose""'))
graph export "Figures/support.pdf", replace

*H2/RQ1 effects lasso
lasso linear effects i.education_group i.age i.male 1.dem 1.rep i.race_group i.income_group homeowner_binary home_type i.employment govt_assistance white_therm black_therm biden_therm trump_therm republican_therm democrat_therm affordability affordable_area know_others_difficulty neighborhood_bonds affordable_housing_support_pre, rseed(1234)
local effects_ctl=e(allvars_sel) 

*H2/RQ1 effects reg
reg effects characteristics_treatment effects_treatment effects_first two_first `effects_ctl', robust
est store h2effects

*difference in treatment effects
lincom characteristics_treatment-effects_treatment

estout h2support h2effects using "Tables/h2support-effects.tex", label keep(characteristics_treatment effects_treatment effects_first two_first) style(tex) replace varwidth(25) collabels("") cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N, fmt(%9.0f) labels("N")) starlevels(* 0.05 ** 0.01 *** .005)

*exploratory with no lasso covariates for verification
reg effects characteristics_treatment effects_treatment effects_first two_first, robust
lincom characteristics_treatment-effects_treatment

reg effects characteristics_treatment##two_first effects_treatment##two_first effects_first `effects_ctl', robust
est store h2effects_twofirst

*substantive effect sizes
gen binary_support=(support>=2.5) if support!=.
gen three_support=(support>=3) if support!=.
gen binary_effects=(effects>=3) if effects!=.
bysort characteristics_treatment effects_treatment: su support binary_support three_support effects binary_effects

*exploratory for targeted versus untargeted
lasso linear effects_targeted i.education_group i.age i.male 1.dem 1.rep i.race_group i.income_group homeowner_binary home_type i.employment govt_assistance white_therm black_therm biden_therm trump_therm republican_therm democrat_therm affordability affordable_area know_others_difficulty neighborhood_bonds affordable_housing_support_pre, rseed(1234)
local effects_targeted_ctl=e(allvars_sel) 

reg effects_targeted characteristics_treatment effects_treatment effects_first two_first `effects_targeted_ctl', robust
est store h2effects_targeted
lincom characteristics_treatment-effects_treatment

reg effects_targeted characteristics_treatment##two_first effects_treatment##two_first effects_first `effects_targeted_ctl', robust
est store h2effects_targeted_twof

lasso linear effects_untargeted i.education_group i.age i.male 1.dem 1.rep i.race_group i.income_group homeowner_binary home_type i.employment govt_assistance white_therm black_therm biden_therm trump_therm republican_therm democrat_therm affordability affordable_area know_others_difficulty neighborhood_bonds affordable_housing_support_pre, rseed(1234)
local effects_untargeted_ctl=e(allvars_sel) 

reg effects_untargeted characteristics_treatment effects_treatment effects_first two_first `effects_untargeted_ctl', robust
est store h2effects_untargeted
lincom characteristics_treatment-effects_treatment

reg effects_untargeted characteristics_treatment##two_first effects_treatment##two_first effects_first `effects_untargeted_ctl', robust
est store h2effects_untargeted_twof

*Tables 3/B3
estout h2support h2effects h2effects_targeted h2effects_untargeted using "Tables/h2support-effects-with-exploratory.tex", label keep(characteristics_treatment effects_treatment effects_first two_first) style(tex) replace varwidth(25) collabels("") cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N, fmt(%9.0f) labels("N")) starlevels(* 0.05 ** 0.01 *** .005)

*Table B4
estout h2support_twofirst h2effects_twofirst h2effects_targeted_twof h2effects_untargeted_twof using "Tables/h2support-effects-with-exploratory-interactions.tex", label keep(1.characteristics_* 1.effects_* 1.two* effects_first) style(tex) replace varwidth(25) collabels("") cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N, fmt(%9.0f) labels("N")) starlevels(* 0.05 ** 0.01 *** .005)

preserve

rename traffic_8 impact1
rename prop_value_8 impact2
rename ethnic_8 impact3
rename crime_8 impact4
rename green_8 impact5
rename schools_8 impact6
rename traffic_2 impact7
rename prop_value_2 impact8
rename ethnic_2 impact9
rename crime_2 impact10
rename green_2 impact11
rename school_2 impact12

reshape long impact, i(participantId) j(impactnum)

gen targeted=(impactnum==2 | impactnum==4 | impactnum==8 | impactnum==10)

lasso linear impact i.education_group i.age i.male 1.dem 1.rep i.race_group i.income_group homeowner_binary home_type i.employment govt_assistance white_therm black_therm biden_therm trump_therm republican_therm democrat_therm affordability affordable_area know_others_difficulty neighborhood_bonds affordable_housing_support_pre, rseed(1234)
local impact_ctl=e(allvars_sel) 

reg impact characteristics_treatment##effects_treatment##targeted effects_first two_first `impact_ctl', robust cluster(participantId)
est store interaction_effects
lincom 1.effects_treatment+1.effects_treatment#1.targeted
lincom 1.characteristics_treatment+1.characteristics_treatment#1.targeted

*Table B5
estout interaction_effects using "Tables/h2support-effects-interaction.tex", label keep(1.characteristics_treatment 1.characteristics_treatment#1.targeted 1.targeted 1.effects_treatment 1.effects_treatment#1.targeted effects_first two_first) style(tex) replace varwidth(25) collabels("") cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N, fmt(%9.0f) labels("N")) starlevels(* 0.05 ** 0.01 *** .005)

restore 

*bar graph
cibar effects, over(groupnum) graphopts(scheme(lean1) legend(on ring(0) position(1) col(1) bcolor(white) region(lstyle(solid))) ytitle("") ylabel(1 "Much worse" 2 "Somewhat worse" 3 "About the same" 4 "Somewhat better" 5 "Much better"))
graph export "Figures/effects.pdf", replace

*************
*RQ2 section*
*************

/*RQ2: Will the effects of the corrections tested in H2 vary by partisanship (RQ2a), percentage nonwhite in respondent zipcode (RQ2b; white respondents only), home ownership status (RQ2c), or prior support for affordable housing (RQ2d)?*/   

/*To test RQ2 for party, we will estimate versions of the models listed above for H2 among only people who identify with or lean toward one of the two major parties. For each of these models, we will add an indicator for Republicans and separate interactions between the Republican indicator and each of the treatment variables.*/
 
*RQ2a support lasso
lasso linear support i.education_group i.age i.male i.race_group i.income_group homeowner_binary home_type i.employment govt_assistance white_therm black_therm biden_therm trump_therm republican_therm democrat_therm affordability affordable_area know_others_difficulty neighborhood_bonds affordable_housing_support_pre if dem==1 | rep==1, rseed(1234)
local support_ctl=e(allvars_sel) 

*RQ2a support reg
reg support characteristics_treatment##rep effects_treatment##rep effects_first two_first `support_ctl' if dem==1 | rep==1, robust
est store RQ2a_support

*marginal effect of effects treatment for Ds
lincom 1.effects_treatment

*marginal effect of effects treatment for Rs
lincom 1.effects_treatment+1.effects_treatment#1.rep

*marginal effect of characteristics treatment for Ds
lincom 1.effects_treatment

*marginal effect of characteristics treatment for Rs
lincom 1.characteristics_treatment+1.characteristics_treatment#1.rep

*exploratory with no lasso covariates for verification
reg support characteristics_treatment##rep effects_treatment##rep effects_first two_first if dem==1 | rep==1, robust
lincom 1.effects_treatment+1.effects_treatment#1.rep
lincom 1.characteristics_treatment+1.characteristics_treatment#1.rep

*make party variable for Figures
gen party3=.
replace party3=1 if dem==1
replace party3=2 if dem==0 & rep==0
replace party3=3 if rep==1

label def partylab 1 "Democrat" 2 "Independent" 3 "Republican"
label val party3 partylab

*bar graph
cibar support, over1(groupnum) over2(party3) graphopts(scheme(lean1) legend(on ring(0) position(1) col(1) bcolor(white) region(lstyle(solid))) ytitle("Affordable housing support"))
graph export "Figures/supportXparty.pdf", replace

*RQ2a effects lasso
lasso linear effects i.education_group i.age i.male i.race_group i.income_group homeowner_binary home_type i.employment govt_assistance white_therm black_therm biden_therm trump_therm republican_therm democrat_therm affordability affordable_area know_others_difficulty neighborhood_bonds affordable_housing_support_pre if dem==1 | rep==1, rseed(1234)
local effects_ctl=e(allvars_sel) 

*RQ2a effects reg
reg effects characteristics_treatment##rep effects_treatment##rep effects_first two_first `effects_ctl' if dem==1 | rep==1, robust
est store RQ2a_effects

*marginal effect of effects treatment for Ds
lincom 1.effects_treatment

*marginal effect of effects treatment for Rs
lincom 1.effects_treatment+1.effects_treatment#1.rep

*marginal effect of characteristics treatment for Ds
lincom 1.characteristics_treatment

*marginal effect of characteristics treatment for Rs
lincom 1.characteristics_treatment+1.characteristics_treatment#1.rep

*exploratory with no lasso covariates for verification
reg effects characteristics_treatment##rep effects_treatment##rep effects_first two_first if dem==1 | rep==1, robust
lincom 1.effects_treatment+1.effects_treatment#1.rep
lincom 1.characteristics_treatment+1.characteristics_treatment#1.rep

*bar graph
cibar effects, over1(groupnum) over2(party3) graphopts(scheme(lean1) legend(on ring(0) position(1) col(1) bcolor(white) region(lstyle(solid))) ytitle("Perceived effects of affordable housing"))
graph export "Figures/effectsXparty.pdf", replace

/*To test RQ2 for home ownership, we will estimate versions of the models listed above for H2. For each of these models, we will add an indicator for homeowner and separate interactions between the homeowner indicator and each of the treatment variables.*/

*RQ2b support lasso
lasso linear support i.education_group i.age i.male 1.dem 1.rep i.race_group i.income_group home_type i.employment govt_assistance white_therm black_therm biden_therm trump_therm republican_therm democrat_therm affordability affordable_area know_others_difficulty neighborhood_bonds affordable_housing_support_pre, rseed(1234)
local support_ctl=e(allvars_sel) 

*RQ2b support reg
reg support characteristics_treatment##homeowner_binary effects_treatment##homeowner_binary  effects_first two_first `support_ctl', robust
est store RQ2b_support

*marginal effect of effects treatment for non-homeowners
lincom 1.effects_treatment

*marginal effect of effects treatment for homeowners
lincom 1.effects_treatment+1.effects_treatment#1.homeowner_binary

*marginal effect of characteristics treatment for non-homeowners
lincom 1.characteristics_treatment

*marginal effect of characteristics treatment for homeowners
lincom 1.characteristics_treatment+1.characteristics_treatment#1.homeowner_binary

*exploratory with no lasso covariates for verification
reg support characteristics_treatment##homeowner_binary effects_treatment##homeowner_binary effects_first two_first, robust
lincom 1.effects_treatment+1.effects_treatment#1.homeowner_binary
lincom 1.characteristics_treatment+1.characteristics_treatment#1.homeowner_binary

*label homeowner variable for Figures
label def homelab 0 "Not homeowner" 1 "Homeowner"
label val homeowner_binary homelab

*bar graph
cibar support, over1(groupnum) over2(homeowner_binary) graphopts(scheme(lean1) legend(on ring(0) position(1) col(1) bcolor(white) region(lstyle(solid))) ytitle("Affordable housing support"))
graph export "Figures/supportXhomeowner.pdf", replace

*RQ2b effects lasso
lasso linear effects i.education_group i.age i.male 1.dem 1.rep i.race_group i.income_group home_type i.employment govt_assistance white_therm black_therm biden_therm trump_therm republican_therm democrat_therm affordability affordable_area know_others_difficulty neighborhood_bonds affordable_housing_support_pre, rseed(1234)
local effects_ctl=e(allvars_sel) 

*RQ2b effects reg
reg effects characteristics_treatment##homeowner_binary effects_treatment##homeowner_binary effects_first two_first `effects_ctl', robust
est store RQ2b_effects

*marginal effect of effects treatment for non-homeowners
lincom 1.effects_treatment

*marginal effect of effects treatment for homeowners
lincom 1.effects_treatment+1.effects_treatment#1.homeowner_binary

*marginal effect of characteristics treatment for non-homeowners
lincom 1.characteristics_treatment

*marginal effect of characteristics treatment for homeowners
lincom 1.characteristics_treatment+1.characteristics_treatment#1.homeowner_binary

*exploratory with no lasso covariates for verification
reg effects characteristics_treatment##homeowner_binary effects_treatment##homeowner_binary effects_first two_first, robust
lincom 1.effects_treatment+1.effects_treatment#1.homeowner_binary
lincom 1.characteristics_treatment+1.characteristics_treatment#1.homeowner_binary

*bar graph
cibar effects, over1(groupnum) over2(homeowner_binary) graphopts(scheme(lean1) legend(on ring(0) position(1) col(1) bcolor(white) region(lstyle(solid))) ytitle("Perceived effects of affordable housing"))
graph export "Figures/effectsXhomeowner.pdf", replace

/*To test RQ2 for prior support, we will estimate versions of the models listed above for H2. For each of these models, we will add a variable for prior support (scale of 1-4, 4=strong support) and separate interactions between prior support indicator and each of the treatment variables.*/

*RQ2c support lasso
lasso linear support i.education_group i.age i.male 1.dem 1.rep i.race_group i.income_group homeowner_binary home_type i.employment govt_assistance white_therm black_therm biden_therm trump_therm republican_therm democrat_therm affordability affordable_area know_others_difficulty neighborhood_bonds, rseed(1234)
local support_ctl=e(allvars_sel) 

*RQ2c support reg

*affordable housing support moderator; entered linearly 
reg support characteristics_treatment##c.affordable_housing_support_pre effects_treatment##c.affordable_housing_support_pre effects_first two_first `support_ctl', robust
est store RQ2c_support

*omitting marginal effects

*exploratory with no lasso covariates for verification
reg support characteristics_treatment##c.affordable_housing_support_pre effects_treatment##c.affordable_housing_support_pre effects_first two_first, robust

*exploratory: affordable housing support moderator with median split
gen affordable_housing_support_med=affordable_housing_support_pre>3 & affordable_housing_support_pre!=.

*Table B14
reg support characteristics_treatment##ib1.affordable_housing_support_med effects_treatment##ib1.affordable_housing_support_med effects_first two_first `effects_ctl', robust
est store pretreatsplit
estout pretreatsplit using "Tables/pretreatsplit.tex", label style(tex) keep(1.char* 1.effects* 1.rep *_first) replace varwidth(25) collabels("") cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N, fmt(%9.0f) labels("N")) starlevels(* 0.05 ** 0.01 *** .005) noomitted

*exploratory with no lasso covariates for verification
reg support characteristics_treatment##ib1.affordable_housing_support_med effects_treatment##ib1.affordable_housing_support_med, robust

*label median split variable for Figures
label def afflab 0 "Less supportive" 1 "More supportive"
label val affordable_housing_support_med afflab

*bar graph
cibar support, over1(groupnum) over2(affordable_housing_support_med) graphopts(scheme(lean1) legend(on ring(0) position(1) col(1) bcolor(white) region(lstyle(solid))) ytitle("Affordable housing support"))
graph export "Figures/supportXpriorsupport.pdf", replace

*RQ2c effects lasso
lasso linear effects i.education_group i.age i.male 1.dem 1.rep i.race_group i.income_group homeowner_binary home_type i.employment govt_assistance white_therm black_therm biden_therm trump_therm republican_therm democrat_therm affordability affordable_area know_others_difficulty neighborhood_bonds, rseed(1234)
local effects_ctl=e(allvars_sel) 

*RQ2c effects reg

*affordable housing support moderator; entered linearly
reg effects characteristics_treatment##c.affordable_housing_support_pre effects_treatment##c.affordable_housing_support_pre effects_first two_first `effects_ctl', robust
est store RQ2c_effects

*exploratory with no lasso covariates for verification
reg effects characteristics_treatment##c.affordable_housing_support_pre effects_treatment##c.affordable_housing_support_pre two_first, robust

*exploratory: affordable housing support moderator with median split (note there are a ton at a mean of 3 so this is 42% above that at 3.5/4, could also split for 32% below that at 1-2.5
reg effects characteristics_treatment##ib1.affordable_housing_support_med effects_treatment##ib1.affordable_housing_support_med `effects_ctl', robust

*exploratory with no lasso covariates for verification
reg effects characteristics_treatment##ib1.affordable_housing_support_med effects_treatment##ib1.affordable_housing_support_med, robust

*bar graph
cibar effects, over1(groupnum) over2(affordable_housing_support_med) graphopts(scheme(lean1) legend(on ring(0) position(1) col(1) bcolor(white) region(lstyle(solid))) ytitle("Perceived effects of affordable housing"))
graph export "Figures/effectsXpriorsupport.pdf", replace

/*To test RQ2 for percent non-white in respondent zipcode, we will estimate versions of the models listed above for H2 among white respondents only. For each of these models, we will add a variable with tercile indicators for low and medium nonwhite population (calculated using percent nonwhite in respondent zipcodes) and separate interactions between the tercile indicators and each of the treatment variables.*/

*RQ2d support lasso
lasso linear support i.education_group i.age i.male 1.dem 1.rep i.race_group i.income_group homeowner_binary home_type i.employment govt_assistance white_therm black_therm biden_therm trump_therm republican_therm democrat_therm affordability affordable_area know_others_difficulty neighborhood_bonds affordable_housing_support_pre if white==1, rseed(1234)
local support_ctl=e(allvars_sel) 

*RQ2d support reg terc
reg support characteristics_treatment##nonwhite_pct_terc effects_treatment##ib1.nonwhite_pct_terc effects_first two_first `support_ctl' if white==1, robust
est store RQ2d_support_terc

*marginal effect of effects treatment if lowest tercile of nonwhite population
lincom 1.effects_treatment
 
*marginal effect of effects treatment if second tercile of nonwhite population
lincom 1.effects_treatment+1.effects_treatment#2.nonwhite_pct_terc

*marginal effect of effects treatment if top tercile of nonwhite population
lincom 1.effects_treatment+1.effects_treatment#3.nonwhite_pct_terc

*marginal effect of characteristics treatment if lowest tercile of nonwhite population
lincom 1.characteristics_treatment
 
*marginal effect of characteristics treatment if second tercile of nonwhite population
lincom 1.characteristics_treatment+1.characteristics_treatment#2.nonwhite_pct_terc

*marginal effect of characteristics treatment if top tercile of nonwhite population
lincom 1.characteristics_treatment+1.characteristics_treatment#3.nonwhite_pct_terc

*exploratory with no lasso covariates for verification
reg support characteristics_treatment##nonwhite_pct_terc effects_treatment##i.nonwhite_pct_terc effects_first two_first if white==1, robust
lincom 1.effects_treatment+1.effects_treatment#1.nonwhite_pct_terc
lincom 1.characteristics_treatment+1.characteristics_treatment#1.nonwhite_pct_terc

*RQ2d support reg quintile
reg support characteristics_treatment##nonwhite_pct_quint effects_treatment##i.nonwhite_pct_quint effects_first two_first `support_ctl' if white==1, robust
est store RQ2d_support

*marginal effects omitted

*exploratory with no lasso covariates for verification
reg support characteristics_treatment##nonwhite_pct_quint effects_treatment##i.nonwhite_pct_quint effects_first two_first if white==1, robust
lincom 1.effects_treatment+1.effects_treatment#1.nonwhite_pct_quint
lincom 1.characteristics_treatment+1.characteristics_treatment#1.nonwhite_pct_quint

*bar graph
cibar support, over1(groupnum) over2(nonwhite_pct_quint) graphopts(scheme(lean1) legend(on ring(0) position(1) col(1) bcolor(white) region(lstyle(solid))) ytitle("Affordable housing support") xtitle("Nonwhite percentage (quintile)"))
graph export "Figures/supportXnonwhitequint.pdf", replace

*RQ2d effects lasso
lasso linear effects i.education_group i.age i.male 1.dem 1.rep i.race_group i.income_group homeowner_binary home_type i.employment govt_assistance white_therm black_therm biden_therm trump_therm republican_therm democrat_therm affordability affordable_area know_others_difficulty neighborhood_bonds affordable_housing_support_pre if white==1, rseed(1234)
local effects_ctl=e(allvars_sel) 

*RQ2d effects reg terc
reg effects characteristics_treatment##nonwhite_pct_terc effects_treatment##i.nonwhite_pct_terc effects_first two_first `effects_ctl' if white==1, robust
est store RQ2d_effects_terc

*marginal effect of effects treatment if lowest tercile of nonwhite population
lincom 1.effects_treatment
 
*marginal effect of effects treatment if second tercile of nonwhite population
lincom 1.effects_treatment+1.effects_treatment#2.nonwhite_pct_terc

*marginal effect of effects treatment if top tercile of nonwhite population
lincom 1.effects_treatment+1.effects_treatment#3.nonwhite_pct_terc

*marginal effect of characteristics treatment if lowest tercile of nonwhite population
lincom 1.characteristics_treatment
 
*marginal effect of characteristics treatment if second tercile of nonwhite population
lincom 1.characteristics_treatment+1.characteristics_treatment#2.nonwhite_pct_terc

*marginal effect of characteristics treatment if top tercile of nonwhite population
lincom 1.characteristics_treatment+1.characteristics_treatment#3.nonwhite_pct_terc

*exploratory with no lasso covariates for verification
reg effects characteristics_treatment##nonwhite_pct_terc effects_treatment##i.nonwhite_pct_terc effects_first two_first if white==1, robust
lincom 1.effects_treatment+1.effects_treatment#1.nonwhite_pct_terc
lincom 1.characteristics_treatment+1.characteristics_treatment#1.nonwhite_pct_terc

*RQ2d effects reg quintile
reg effects characteristics_treatment##nonwhite_pct_quint effects_treatment##i.nonwhite_pct_quint effects_first two_first `support_ctl' if white==1, robust
est store RQ2d_effects

*marginal effects omitted 

*exploratory with no lasso covariates for verification
reg effects effects_treatment##i.nonwhite_pct_quint characteristics_treatment##nonwhite_pct_quint effects_first two_first if white==1, robust

*bar graph
cibar effects, over1(groupnum) over2(nonwhite_pct_quint) graphopts(scheme(lean1) legend(on ring(0) position(1) col(1) bcolor(white) region(lstyle(solid))) ytitle("Perceived effects of affordable housing") xtitle("Nonwhite percentage (quintile)"))
graph export "Figures/effectsXnonwhitequint.pdf", replace

*Table B6
estout RQ2a_support RQ2a_effects using "Tables/rq2a.tex", label style(tex) keep(1.char* 1.effects* 1.rep *_first) replace varwidth(25) collabels("") cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N, fmt(%9.0f) labels("N")) starlevels(* 0.05 ** 0.01 *** .005) noomitted

*Table B7
estout RQ2b_support RQ2b_effects using "Tables/rq2b.tex", label style(tex) keep(1.char* 1.effects* 1.homeowner_binary *_first) replace varwidth(25) collabels("") cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N, fmt(%9.0f) labels("N")) starlevels(* 0.05 ** 0.01 *** .005) noomitted

*Table B8
estout RQ2c_support RQ2c_effects using "Tables/rq2c.tex", label style(tex) keep(1.char* 1.effects* affordable_housing_support_pre *_first) replace varwidth(25) collabels("") cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N, fmt(%9.0f) labels("N")) starlevels(* 0.05 ** 0.01 *** .005) noomitted

*Table B9
estout RQ2d_support_terc RQ2d_effects_terc using "Tables/rq2d.tex", label style(tex) keep(1.char* 1.effects* 2.nonwhite_pct_terc 3.nonwhite_pct_terc *_first) replace varwidth(25) collabels("") cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N, fmt(%9.0f) labels("N")) starlevels(* 0.05 ** 0.01 *** .005) noomitted

estout RQ2d_support RQ2d_effects using "Tables/rq2dquint.tex", label style(tex) keep(1.char* 1.effects* 2.nonwhite_pct_quint 3.nonwhite_pct_quint 4.nonwhite_pct_quint 5.nonwhite_pct_quint *_first) replace varwidth(25) collabels("") cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N, fmt(%9.0f) labels("N")) starlevels(* 0.05 ** 0.01 *** .005) noomitted

/*Exploratory HTE by difference in feelings (white/black) among white respondents only*/

*support lasso - remove race_group
quietly lasso linear support i.education_group i.age i.male 1.dem 1.rep i.income_group homeowner_binary home_type i.employment govt_assistance white_therm black_therm biden_therm trump_therm republican_therm democrat_therm affordability affordable_area know_others_difficulty neighborhood_bonds affordable_housing_support_pre if white==1, rseed(1234)
local support_ctl=e(allvars_sel) 

*feeling diff terc
reg support characteristics_treatment##ib0.feeling_diff_terc effects_treatment##ib0.feeling_diff_terc effects_first two_first `support_ctl' if white==1, robust
est store diff1 

*feeling diff terc no controls
reg support characteristics_treatment##ib0.feeling_diff_terc effects_treatment##ib0.feeling_diff_terc effects_first two_first if white==1, robust
est store diff1_nc

*feeling diff linear
reg support characteristics_treatment##c.feeling_diff effects_treatment##c.feeling_diff effects_first two_first `support_ctl' if white==1, robust

*effects lasso - remove race_group
quietly lasso linear effects i.education_group i.age i.male 1.dem 1.rep i.income_group homeowner_binary home_type i.employment govt_assistance white_therm black_therm biden_therm trump_therm republican_therm democrat_therm affordability affordable_area know_others_difficulty neighborhood_bonds affordable_housing_support_pre if white==1, rseed(1234)
local effects_ctl=e(allvars_sel) 

*feeling diff terc
reg effects characteristics_treatment##ib0.feeling_diff_terc effects_treatment##ib0.feeling_diff_terc effects_first two_first `effects_ctl' if white==1, robust
est store diff2

*feeling diff terc no controls
reg effects characteristics_treatment##ib0.feeling_diff_terc effects_treatment##ib0.feeling_diff_terc effects_first two_first if white==1, robust
est store diff2_nc

*feeling diff linear
reg effects characteristics_treatment##c.feeling_diff effects_treatment##c.feeling_diff effects_first two_first `effects_ctl' if white==1, robust

estout diff1 diff2 using "Tables/diffhte.tex", label style(tex) keep(1.char* 1.effects* 1.feeling_d* 0.feeling_d* *_first) replace varwidth(25) collabels("") cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N, fmt(%9.0f) labels("N")) starlevels(* 0.05 ** 0.01 *** .005) noomitted

*Table B13
estout diff1_nc diff1 diff2_nc diff2 using "Tables/diffhte_nc.tex", label style(tex) keep(1.char* 1.effects* 1.feeling_d* 2.feeling_d* *_first) replace varwidth(25) collabels("") cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N, fmt(%9.0f) labels("N")) starlevels(* 0.05 ** 0.01 *** .005) noomitted

/*Exploratory HTE by race*/

*support lasso - remove race_group
quietly lasso linear support i.education_group i.age i.male 1.dem 1.rep i.income_group homeowner_binary home_type i.employment govt_assistance white_therm black_therm biden_therm trump_therm republican_therm democrat_therm affordability affordable_area know_others_difficulty neighborhood_bonds affordable_housing_support_pre, rseed(1234)
local support_ctl=e(allvars_sel) 

*by race (white vs. not)
reg support characteristics_treatment##white effects_treatment##white effects_first two_first `support_ctl', robust
est store A3

*effects lasso - remove race_group
quietly lasso linear effects i.education_group i.age i.male 1.dem 1.rep i.income_group homeowner_binary home_type i.employment govt_assistance white_therm black_therm biden_therm trump_therm republican_therm democrat_therm affordability affordable_area know_others_difficulty neighborhood_bonds affordable_housing_support_pre, rseed(1234)
local effects_ctl=e(allvars_sel) 

*by race (white vs. not)
reg effects characteristics_treatment##white effects_treatment##white effects_first two_first `effects_ctl', robust
est store B3

*support lasso - remove race_group and race therm
quietly lasso linear support i.education_group i.age i.male 1.dem 1.rep i.income_group homeowner_binary home_type i.employment govt_assistance biden_therm trump_therm republican_therm democrat_therm affordability affordable_area know_others_difficulty neighborhood_bonds affordable_housing_support_pre, rseed(1234)
local support_ctl=e(allvars_sel) 

*by race (white vs. not)
reg support characteristics_treatment##white effects_treatment##white effects_first two_first `support_ctl', robust
est store A2

*effects lasso - remove race_group and race therm
quietly lasso linear effects i.education_group i.age i.male 1.dem 1.rep i.income_group homeowner_binary home_type i.employment govt_assistance biden_therm trump_therm republican_therm democrat_therm affordability affordable_area know_others_difficulty neighborhood_bonds affordable_housing_support_pre, rseed(1234)
local effects_ctl=e(allvars_sel) 

*by race (white vs. not)
reg effects characteristics_treatment##white effects_treatment##white effects_first two_first `effects_ctl', robust
est store B2

*by race (white vs. not) - no controls
reg support characteristics_treatment##white effects_treatment##white effects_first two_first, robust
est store A1

*by race (white vs. not) - no controls
reg effects characteristics_treatment##white effects_treatment##white effects_first two_first, robust
est store B1

*Table B12
estout A1 A2 A3 B1 B2 B3 using "Tables/whitehte.tex", label style(tex) keep(1.char* 1.effects* 1.whit* *_first) replace varwidth(25) collabels("") cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N, fmt(%9.0f) labels("N")) starlevels(* 0.05 ** 0.01 *** .005) noomitted

estout A1 A2 A3 B1 B2 B3 using "Tables/whitehte_allcov.tex", label style(tex) replace varwidth(25) collabels("") cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N, fmt(%9.0f) labels("N")) starlevels(* 0.05 ** 0.01 *** .005) noomitted

*********************
*Manipulation checks*
*********************

*The models testing effects on the manipulation checks will also include a control for the order in which they appear (again, an indicator for effects appearing first instead of characteristics).

gen mc_effects_first=(FL_537_DO_manipulationcheck_effe==1)

/*Manipulation checks: To test the effects of the treatment on respondent knowledge, we will run the following models at the respondent level: 

Y = B0 + B1*effects_treatment + B2*characteristics_treatment

where Y = post-treatment belief accuracy about the effects and characteristics of affordable housing (estimated separately)*/

*MC effects lasso
lasso linear effects_accuracy i.education_group i.age i.male 1.dem 1.rep i.race_group i.income_group homeowner_binary home_type i.employment govt_assistance white_therm black_therm biden_therm trump_therm republican_therm democrat_therm affordability affordable_area know_others_difficulty neighborhood_bonds affordable_housing_support_pre, rseed(1234)
local effects_accuracy_ctl=e(allvars_sel) 

*MC effects reg
reg effects_accuracy characteristics_treatment effects_treatment effects_first two_first mc_effects_first `effects_accuracy_ctl', robust
est store MCeffects

*difference in treatment effects
lincom characteristics_treatment-effects_treatment

*exploratory with no lasso covariates for verification
reg effects_accuracy characteristics_treatment effects_treatment effects_first two_first mc_effects_first, robust
lincom characteristics_treatment-effects_treatment

bysort groupnum: su effects_accuracy characteristics_accuracy

*bar graph
cibar effects_accuracy, over(groupnum) graphopts(scheme(lean1) legend(on ring(0) position(1) col(1) bcolor(white) region(lstyle(solid))) title("Proportion correct: Effects of affordable housing",size(*.8)) ytitle(""))
graph export "Figures/effects_accuracy.pdf", replace

*MC characteristics lasso
lasso linear characteristics_accuracy i.education_group i.age i.male 1.dem 1.rep i.race_group i.income_group homeowner_binary home_type i.employment govt_assistance white_therm black_therm biden_therm trump_therm republican_therm democrat_therm affordability affordable_area know_others_difficulty neighborhood_bonds affordable_housing_support_pre, rseed(1234)
local characteristics_accuracy_ctl=e(allvars_sel) 

*MC characteristics reg
reg characteristics_accuracy characteristics_treatment effects_treatment effects_first two_first mc_effects_first `characteristics_accuracy_ctl', robust
est store MCcharacteristics

*difference in treatment effects
lincom characteristics_treatment-effects_treatment

*exploratory with no lasso covariates for verification
reg characteristics_accuracy characteristics_treatment effects_treatment effects_first two_first mc_effects_first, robust
lincom characteristics_treatment-effects_treatment

*bar graph
cibar characteristics_accuracy, over(groupnum) graphopts(scheme(lean1) legend(on ring(0) position(1) col(1) bcolor(white) region(lstyle(solid))) title("Proportion correct: Characteristics of affordable housing",size(*.8)) ytitle(""))
graph export "Figures/characteristics_accuracy.pdf", replace

*Table B1
estout MCcharacteristics MCeffects using "Tables/mcs.tex", label style(tex) keep (*_treatment *_first) replace varwidth(25) collabels("") cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N, fmt(%9.0f) labels("N")) starlevels(* 0.05 ** 0.01 *** .005)

*****************************
*Respondent-distance section*
*****************************

*save the state of the data before the reshape
preserve

*************************************
*Combined measure of support (H1/H3)*
*************************************

*reshape to respondent-distance level - support combined
gen support_level_18=support_18_combined
gen support_level_2=support_2_combined
gen support_level_50=support_state_combined

reshape long support_level_, i(participantId) j(level)

*so it shows up first in graphs
replace level=.18 if level==18 

gen oneeighth=(level<2)
gen twomiles=(level==2)
gen state=(level==50)

egen levelnum=group(level)

label def leveldef 1 "1/8 mile away" 2 "Two miles away" 3 "State level"
label val levelnum leveldef

*create a numeric ID variable to use for clustering and fixed effects
egen newid=group(participantId)

*set it as the ID variable for fixed effects
xtset newid 

/*H1: Respondents will support building affordable housing more the further it is from where they live. 

To test H1, we will run the following model at the respondent-distance level with respondent fixed effects and standard errors clustered by respondent:

Y = B0 + B1*distance (factor: state or two miles or 1/8th of mile)

where Y = mean support for affordable housing*/

xtreg support_level_ i.oneeighth i.twomiles, fe cluster(newid) 
est store supportlevelcombined

*difference in support (one-eigth vs. state-level)
lincom 1.oneeighth

*difference in support (two miles vs. state-level)
lincom 1.twomiles

*difference in support (one-eighth vs. two miles)
lincom 1.oneeighth-1.twomiles

cibar support_level_, over1(levelnum) graphopts(scheme(lean1) legend(on ring(0) position(1) col(1) bcolor(white) region(lstyle(solid))) ytitle("") legend(off) xlabel(1 "1/8 mile away" 2 "Two miles away" 3 "State level") ylabel(4 `""Strongly" "support""' 3 `""Somewhat" "support""' 2 `""Somewhat" "oppose""' 1 `""Strongly" "oppose""'))
graph export "Figures/supportcombXlevel.pdf", replace

/*H3: The effects of the corrections tested in H2 will be stronger as the distance from where the respondent lives increases (state vs. two miles vs. ⅛ of a mile for support, two miles versus ⅛ of a mile for effects).

To test H3, we will run the following models at the respondent-distance level with respondent fixed effects and standard errors clustered by respondent:

Y = B0 + B1*effects_treatment + B2*characteristiscs_treatment + B3*one_eighth + B4*two_miles + B5*effects_treatmentXone_eighth + B6*effects_treatmentXtwo_miles + B7*characteristics_treatmentXone_eight + B8*characteristics_treatmentXtwo_miles

where Y = mean support for affordable housing. We will also calculate relevant marginal effects and differences in marginal effects per H3 above.*/
 
xtreg support_level_ characteristics_treatment##i.oneeighth##i.twomiles effects_treatment##i.oneeighth##i.twomiles, fe cluster(newid) 
*add marginal effects

*deviation: omit fixed effects so we can estimate effect of both treatments
reg support_level_ characteristics_treatment##i.oneeighth##i.twomiles effects_treatment##i.oneeighth##i.twomiles, cluster(newid) 
est store supporttreatlevelcombined

*marginal effect of effects treatment at state level
lincom 1.effects_treatment

*marginal effect of effects treatment at one-eighth level
lincom 1.effects_treatment+1.effects_treatment#1.oneeighth

*marginal effect of effects treatment at two mile level
lincom 1.effects_treatment+1.effects_treatment#1.twomiles

*difference in marginal effects - one-eighth vs. two miles
lincom 1.effects_treatment#1.oneeighth-1.effects_treatment#1.twomiles

*marginal effect of characteristics treatment at state level
lincom 1.characteristics_treatment

*marginal effect of characteristics treatment at one-eighth level
lincom 1.characteristics_treatment+1.characteristics_treatment#1.oneeighth

*marginal effect of characteristics treatment at two mile level
lincom 1.characteristics_treatment+1.characteristics_treatment#1.twomiles

*difference in marginal effects - one-eighth vs. two miles
lincom 1.characteristics_treatment#1.oneeighth-1.characteristics_treatment#1.twomiles

*difference in marginal effects at state level
lincom 1.effects_treatment-1.characteristics_treatment

*difference in marginal effects at two miles level
lincom (1.effects_treatment+1.effects_treatment#1.twomiles)-(1.characteristics_treatment+1.characteristics_treatment#1.twomiles)

*difference in marginal effects at one-eighth level
lincom (1.effects_treatment+1.effects_treatment#1.oneeighth)-(1.characteristics_treatment+1.characteristics_treatment#1.oneeighth)

cibar support_level_, over1(groupnum) over2(levelnum) graphopts(scheme(lean1) legend(on ring(0) position(1) col(1) bcolor(white) region(lstyle(solid))) ytitle("") ylabel(4 `""Strongly" "support""' 3 `""Somewhat" "support""' 2 `""Somewhat" "oppose""' 1 `""Strongly" "oppose""'))
graph export "Figures/supportcombtreatXlevel.pdf", replace

*exploratory
bysort two_first: reg support_level_ effects_treatment##i.oneeighth##i.twomiles characteristics_treatment##i.oneeighth##i.twomiles, cluster(newid) 

*exploratory analysis - combined treatment
gen combined_treatment=0
replace combined_treatment=1 if effects_treatment==1 | characteristics_treatment==1

*deviation: omit fixed effects so we can estimate effect of both treatments
reg support_level_ combined_treatment##i.oneeighth##i.twomiles, cluster(newid) 

*marginal effect of combined treatment at state level
lincom 1.combined_treatment

*marginal effect of effects treatment at one-eighth level
lincom 1.combined_treatment+1.combined_treatment#1.oneeighth

*marginal effect of effects treatment at two mile level
lincom 1.combined_treatment+1.combined_treatment#1.twomiles

*difference in marginal effects - one-eighth vs. two miles
lincom 1.combined_treatment#1.oneeighth-1.combined_treatment#1.twomiles

cibar support_level_, over1(combined_treatment) over2(levelnum) graphopts(scheme(lean1) legend(on ring(0) position(1) col(1) bcolor(white) region(lstyle(solid))) ytitle("") ylabel(4 `""Strongly" "support""' 3 `""Somewhat" "support""' 2 `""Somewhat" "oppose""' 1 `""Strongly" "oppose""'))
graph export "Figures/supportcombtreatcombXlevel.pdf", replace

*restore the data to its state before the reshape
restore

*******************************
*Support measure alone (H1/H3)*
*******************************

*robustness test - support alone
preserve

*reshape to respondent-distance level - support alone
gen support_level_18=support_8th
gen support_level_2=support_2
gen support_level_50=support_state

reshape long support_level_, i(participantId) j(level)

*so it shows up first in graphs
replace level=.18 if level==18 

gen oneeighth=(level<2)
gen twomiles=(level==2)
gen state=(level==50)

*correspondence between support and vote by level
gen vote_at_level=.
replace vote_at_level=vote_8th if oneeighth==1
replace vote_at_level=vote_2 if twomiles==1
replace vote_at_level=vote_state if state==1

reg vote_at_level c.support_level_##oneeighth##state, robust

bysort level: su support_level_ vote_at_level 
bysort level: pwcorr support_level_ vote_at_level

egen levelnum=group(level)

label def leveldef 1 "1/8 mile away" 2 "Two miles away" 3 "State level"
label val levelnum leveldef

*create a numeric ID variable to use for clustering and fixed effects
egen newid=group(participantId)

*set it as the ID variable for fixed effects
xtset newid 

/*H1: Respondents will support building affordable housing more the further it is from where they live. 

To test H1, we will run the following model at the respondent-distance level with respondent fixed effects and standard errors clustered by respondent:

Y = B0 + B1*distance (factor: state or two miles or 1/8th of mile)

where Y = mean support for affordable housing*/

xtreg support_level_ i.oneeighth i.twomiles, fe cluster(newid) 
est store supportlevelonly

*difference in support (one-eigth vs. state-level)
lincom 1.oneeighth

*difference in support (two miles vs. state-level)
lincom 1.twomiles

*difference in support (one-eighth vs. two miles)
lincom 1.oneeighth-1.twomiles

cibar support_level_, over1(levelnum) graphopts(scheme(lean1) legend(on ring(0) position(1) col(1) bcolor(white) region(lstyle(solid))) ytitle("Affordable housing support (only)"))
graph export "Figures/supportonlyXlevel.pdf", replace

/*H3: The effects of the corrections tested in H2 will be stronger as the distance from where the respondent lives increases (state vs. two miles vs. ⅛ of a mile for support, two miles versus ⅛ of a mile for effects).

To test H3, we will run the following models at the respondent-distance level with respondent fixed effects and standard errors clustered by respondent:

Y = B0 + B1*effects_treatment + B2*characteristiscs_treatment + B3*one_eighth + B4*two_miles + B5*effects_treatmentXone_eighth + B6*effects_treatmentXtwo_miles + B7*characteristics_treatmentXone_eight + B8*characteristics_treatmentXtwo_miles

where Y = mean support for affordable housing. We will also calculate relevant marginal effects and differences in marginal effects per H3 above.*/
 
xtreg support_level_ characteristics_treatment##i.oneeighth##i.twomiles effects_treatment##i.oneeighth##i.twomiles, fe cluster(newid) 

*deviation: omit fixed effects so we can estimate effect of both treatments
reg support_level_ characteristics_treatment##i.oneeighth##i.twomiles effects_treatment##i.oneeighth##i.twomiles, cluster(newid) 
est store supporttreatlevelonly

*marginal effect of effects treatment at state level
lincom 1.effects_treatment

*marginal effect of effects treatment at one-eighth level
lincom 1.effects_treatment+1.effects_treatment#1.oneeighth

*marginal effect of effects treatment at two mile level
lincom 1.effects_treatment+1.effects_treatment#1.twomiles

*difference in marginal effects - one-eighth vs. two miles
lincom 1.effects_treatment#1.oneeighth-1.effects_treatment#1.twomiles

*marginal effect of characteristics treatment at state level
lincom 1.characteristics_treatment

*marginal effect of characteristics treatment at one-eighth level
lincom 1.characteristics_treatment+1.characteristics_treatment#1.oneeighth

*marginal effect of characteristics treatment at two mile level
lincom 1.characteristics_treatment+1.characteristics_treatment#1.twomiles

*difference in marginal effects - one-eighth vs. two miles
lincom 1.characteristics_treatment#1.oneeighth-1.characteristics_treatment#1.twomiles

*difference in marginal effects at state level
lincom 1.effects_treatment-1.characteristics_treatment

*difference in marginal effects at two miles level
lincom (1.effects_treatment+1.effects_treatment#1.twomiles)-(1.characteristics_treatment+1.characteristics_treatment#1.twomiles)

*difference in marginal effects at one-eighth level
lincom (1.effects_treatment+1.effects_treatment#1.oneeighth)-(1.characteristics_treatment+1.characteristics_treatment#1.oneeighth)

cibar support_level_, over1(groupnum) over2(levelnum) graphopts(scheme(lean1) legend(on ring(0) position(1) col(1) bcolor(white) region(lstyle(solid))) ytitle("Affordable housing support (only)"))
graph export "Figures/supportonlycombtreatXlevel.pdf", replace

*restore the data to its state before the reshape
restore

****************************
*Vote measure alone (H1/H3)*
****************************

*robustness test - vote alone
preserve

*reshape to respondent-distance level - vote alone
gen vote_level_18=vote_8th
gen vote_level_2=vote_2
gen vote_level_50=vote_state

reshape long vote_level_, i(participantId) j(level)

*so it shows up first in graphs
replace level=.18 if level==18 

gen oneeighth=(level<2)
gen twomiles=(level==2)
gen state=(level==50)

egen levelnum=group(level)

label def leveldef 1 "1/8 mile away" 2 "Two miles away" 3 "State level"
label val levelnum leveldef

*create a numeric ID variable to use for clustering and fixed effects
egen newid=group(participantId)

*set it as the ID variable for fixed effects
xtset newid 

/*H1: Respondents will vote building affordable housing more the further it is from where they live. 

To test H1, we will run the following model at the respondent-distance level with respondent fixed effects and standard errors clustered by respondent:

Y = B0 + B1*distance (factor: state or two miles or 1/8th of mile)

where Y = mean vote for affordable housing*/

xtreg vote_level_ i.oneeighth i.twomiles, fe cluster(newid) 
est store votelevel

*difference in support (one-eigth vs. state-level)
lincom 1.oneeighth

*difference in support (two miles vs. state-level)
lincom 1.twomiles

*difference in support (one-eighth vs. two miles)
lincom 1.oneeighth-1.twomiles

cibar vote_level_, over1(levelnum) graphopts(scheme(lean1) legend(on ring(0) position(1) col(1) bcolor(white) region(lstyle(solid))) ytitle("Affordable housing support (vote)"))
graph export "Figures/voteXlevel.pdf", replace

/*H3: The effects of the corrections tested in H2 will be stronger as the distance from where the respondent lives increases (state vs. two miles vs. ⅛ of a mile for vote, two miles versus ⅛ of a mile for effects).

To test H3, we will run the following models at the respondent-distance level with respondent fixed effects and standard errors clustered by respondent:

Y = B0 + B1*effects_treatment + B2*characteristiscs_treatment + B3*one_eighth + B4*two_miles + B5*effects_treatmentXone_eighth + B6*effects_treatmentXtwo_miles + B7*characteristics_treatmentXone_eight + B8*characteristics_treatmentXtwo_miles

where Y = mean vote for affordable housing. We will also calculate relevant marginal effects and differences in marginal effects per H3 above.*/
 
xtreg vote_level_ characteristics_treatment##i.oneeighth##i.twomiles effects_treatment##i.oneeighth##i.twomiles, fe cluster(newid) 

*deviation: omit fixed effects so we can estimate effect of both treatments
reg vote_level_ characteristics_treatment##i.oneeighth##i.twomiles effects_treatment##i.oneeighth##i.twomiles, cluster(newid) 
est store votetreatlevel

*marginal effect of effects treatment at state level
lincom 1.effects_treatment

*marginal effect of effects treatment at one-eighth level
lincom 1.effects_treatment+1.effects_treatment#1.oneeighth

*marginal effect of effects treatment at two mile level
lincom 1.effects_treatment+1.effects_treatment#1.twomiles

*difference in marginal effects - one-eighth vs. two miles
lincom 1.effects_treatment#1.oneeighth-1.effects_treatment#1.twomiles

*marginal effect of characteristics treatment at state level
lincom 1.characteristics_treatment

*marginal effect of characteristics treatment at one-eighth level
lincom 1.characteristics_treatment+1.characteristics_treatment#1.oneeighth

*marginal effect of characteristics treatment at two mile level
lincom 1.characteristics_treatment+1.characteristics_treatment#1.twomiles

*difference in marginal effects - one-eighth vs. two miles
lincom 1.characteristics_treatment#1.oneeighth-1.characteristics_treatment#1.twomiles

*difference in marginal effects at state level
lincom 1.effects_treatment-1.characteristics_treatment

*difference in marginal effects at two miles level
lincom (1.effects_treatment+1.effects_treatment#1.twomiles)-(1.characteristics_treatment+1.characteristics_treatment#1.twomiles)

*difference in marginal effects at one-eighth level
lincom (1.effects_treatment+1.effects_treatment#1.oneeighth)-(1.characteristics_treatment+1.characteristics_treatment#1.oneeighth)

*bar graph
cibar vote_level_, over1(groupnum) over2(levelnum) graphopts(scheme(lean1) legend(on ring(0) position(1) col(1) bcolor(white) region(lstyle(solid))) ytitle("Affordable housing support (vote)"))
graph export "Figures/votecombtreatXlevel.pdf", replace

*Table B2
estout supportlevelcombined supportlevelonly votelevel using "Tables/supportlevel.tex", label style(tex) keep(1.oneeighth 1.twomiles _cons) replace varwidth(25) collabels("") cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N, fmt(%9.0f) labels("N")) starlevels(* 0.05 ** 0.01 *** .005)

*Table B10
estout supporttreatlevelcombined supporttreatlevelonly votetreatlevel using "Tables/supporttreatlevel.tex", label style(tex) keep(1.characteristics_treatment 1.oneeighth 1.characteristics_treatment#1.oneeighth 1.twomiles 1.characteristics_treatment#1.twomiles 1.effects_treatment 1.effects_treatment#1.oneeighth 1.effects_treatment#1.twomiles) replace varwidth(25) collabels("") cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N, fmt(%9.0f) labels("N")) starlevels(* 0.05 ** 0.01 *** .005) noomitted

*restore the data to its state before the reshape
restore

***********************
*Effects measures (H3)*
***********************

*save the state of the data before the reshape
preserve

*reshape to respondent-distance level - effects
reshape long housing_effect_, i(participantId) j(level)

*so it shows up first in graphs
replace level=.18 if level==18 

gen oneeighth=(level<2)
gen twomiles=(level==2)

egen levelnum=group(level)

label def leveldef 1 "1/8 mile away" 2 "Two miles away" 
label val levelnum leveldef

*create a numeric ID variable to use for clustering and fixed effects
egen newid=group(participantId)

*set it as the ID variable for fixed effects
xtset newid 

xtreg housing_effect_ characteristics_treatment##i.oneeighth effects_treatment##i.oneeighth, fe cluster(newid) 

*deviation: omit fixed effects so we can estimate effect of both treatments
reg housing_effect_ characteristics_treatment##i.oneeighth effects_treatment##i.oneeighth, cluster(newid) 
est store effectstreatlevel

*marginal effect of effects treatment at two mile level
lincom 1.effects_treatment

*marginal effect of effects treatment at one-eighth level
lincom 1.effects_treatment+1.effects_treatment#1.oneeighth

*marginal effect of characteristics treatment at two mile level
lincom 1.characteristics_treatment

*marginal effect of characteristics treatment at one-eighth level
lincom 1.characteristics_treatment+1.characteristics_treatment#1.oneeighth

*difference in marginal effects at two miles level
lincom 1.effects_treatment-1.characteristics_treatment

*difference in marginal effects at one-eighth level
lincom (1.effects_treatment+1.effects_treatment#1.oneeighth)-(1.characteristics_treatment+1.characteristics_treatment#1.oneeighth)

*Table B11
estout effectstreatlevel using "Tables/effectstreatlevel.tex", label style(tex) keep(1.characteristics_treatment 1.oneeighth 1.characteristics_treatment#1.oneeighth 1.effects_treatment 1.effects_treatment#1.oneeighth) replace varwidth(25) collabels("") cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N, fmt(%9.0f) labels("N")) starlevels(* 0.05 ** 0.01 *** .005) noomitted

cibar housing_effect_, over1(groupnum) over2(levelnum) graphopts(scheme(lean1) legend(on ring(0) position(1) col(1) bcolor(white) region(lstyle(solid))) ytitle("") ylabel(1 "Much worse" 2 "Somewhat worse" 3 "About the same" 4 "Somewhat better" 5 "Much better"))
graph export "Figures/effectstreatXlevel.pdf", replace
